//
//  OpenGLWidget.cpp
//  Editor
//
//  Created by Jeppe Nielsen on 11/17/14.
//  Copyright (c) 2014 Jeppe Nielsen. All rights reserved.
//

#include "OpenGLWidget.hpp"
#include <cmath>

OpenGLWidget::OpenGLWidget(QWidget *parent) : QGLWidget(parent) { }

void OpenGLWidget::initializeGL() {
    // Set up the rendering context, define display lists etc.:
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
}

void OpenGLWidget::resizeGL(int w, int h) {
    glViewport(0, 0, (GLint)w, (GLint)h);
}

void OpenGLWidget::Render() {
    update();
}

void OpenGLWidget::paintGL() {
   
   glClear(GL_COLOR_BUFFER_BIT);
   
   static float alpha = 0.0f;
   
   alpha += 0.1f;
   
   float amount = 0.5f + sinf(alpha) * 0.5f;
   
   glClearColor(amount, 0.0, 0.0, 0.0);
}

void OpenGLWidget::makeCurrent(){
  if(context() != context()->currentContext()){
    QGLWidget::makeCurrent();
  }
}
